<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>
        <ui:composition template="./topbartemplate.xhtml">

            <ui:define name="content">
                <p:panel header="#{eventBean.pageTitle}" rendered="#{eventBean.eventExists and not eventBean.event.deleted}">
                    <h:form id = "form">
                        <p:messages />
                        <h:panelGrid columns="2">
                            <p:outputLabel for="eventName" value="Event name:"/>
                            <p:inplace id="eventName" editor="true" disabled="#{not eventBean.isCreator}">
                                <h:inputText value="#{eventBean.event.name}"  />
                            </p:inplace>
                            <p:outputLabel for="eventPlace" value="Event place:"/>
                            <p:inplace id="eventPlace" editor="true" disabled="#{not eventBean.isCreator}">
                                <h:inputText value="#{eventBean.event.place}" />
                            </p:inplace>
                            <p:outputLabel for="eventAddress" value="Event address:"/>
                            <p:inplace id="eventAddress" editor="true" disabled="#{not eventBean.isCreator}">
                                <h:inputText value="#{eventBean.event.address}" />
                            </p:inplace>
                            
                            <p:outputLabel for="country" value="Country:" />
                            <h:outputText id="country" value="#{eventBean.event.country}"/>
                            
                            <p:outputLabel for="city" value="City:" />
                            <p:inplace id="city" editor="true" disabled="#{not eventBean.isCreator}">
                                <p:selectOneMenu  value="#{eventBean.event.city}" style="width:150px" >
                                    <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
                                    <f:selectItems value="#{eventBean.cities}" />
                                </p:selectOneMenu>
                            </p:inplace>
                                                     
                            <p:outputLabel for="starttime" value="Start event:" />
                            <p:inplace id="starttime" editor="true" disabled="#{not eventBean.isCreator}">
                                <p:calendar value="#{eventBean.event.startTime}" navigator="true" effect="fold" pattern="dd/MM/yyyy HH:mm:ss" required="true" >
                                    <p:ajax event="dateSelect" update="@this" />
                                </p:calendar>
                            </p:inplace>
                            
                            <p:outputLabel for="endtime" value="End event:" />
                            <p:inplace id="endtime" editor="true" disabled="#{not eventBean.isCreator}">
                                <p:calendar value="#{eventBean.event.endTime}" navigator="true" effect="fold" pattern="dd/MM/yyyy HH:mm:ss" required="true" validator="#{eventBean.validateEndDate}" >
                                    <p:ajax event="dateSelect" update="@this" />
                                </p:calendar>
                            </p:inplace>
                            
                            <p:outputLabel for="outdoor" value="Outdoor:" />
                            <p:inplace id="outdoor" editor="true" label="#{eventBean.outdoorWellFormatted}" disabled="#{not eventBean.isCreator}">
                                <p:selectBooleanButton value="#{eventBean.event.outdoor}" required="true" onLabel="Yes" offLabel="No" style="width:80px" />
                            </p:inplace>
                            
                            <p:outputLabel for="minTemperature" value="Min. temperature:" />
                            <p:inplace id="minTemperature" editor="true" disabled="#{not eventBean.isCreator}">
                                <p:selectOneMenu  value="#{eventBean.minTemperature}" style="width:150px" >
                                    <p:ajax update="@this" />
                                    <f:selectItem itemLabel="Not enabled" itemValue="Not enabled"/>
                                    <f:selectItems value="#{eventBean.temperatures}" />
                                </p:selectOneMenu>
                            </p:inplace>
                            
                            <p:outputLabel for="maxTemperature" value="Max. temperature:" />
                            <p:inplace id="maxTemperature" editor="true" disabled="#{not eventBean.isCreator}">
                                <p:selectOneMenu  value="#{eventBean.maxTemperature}" style="width:150px" validator="#{eventBean.validateMaximumTemperature}">
                                    <p:ajax update="@this" />
                                    <f:selectItem itemLabel="Not enabled" itemValue="Not enabled"/>
                                    <f:selectItems value="#{eventBean.temperatures}" />
                                </p:selectOneMenu>
                            </p:inplace>
                            
                            <p:outputLabel for="badWeathers" value="Bad weathers:" />
                            <p:inplace id="badWeathers" editor="true" label="#{eventBean.badWeathersWellFormatted}" disabled="#{not eventBean.isCreator}">                               
                                <p:selectManyCheckbox value="#{eventBean.selectedWeatherTypes}"   layout="grid" columns="3" >
                                    <f:selectItem itemLabel="Clear sky" itemValue="Clear sky" />
                                    <f:selectItem itemLabel="Few clouds" itemValue="Few clouds" />
                                    <f:selectItem itemLabel="Scattered clouds" itemValue="Scattered clouds" />
                                    <f:selectItem itemLabel="Broken clouds" itemValue="Broken clouds" />
                                    <f:selectItem itemLabel="Shower rain" itemValue="Shower rain" />
                                    <f:selectItem itemLabel="Rain" itemValue="Rain" />
                                    <f:selectItem itemLabel="Thunderstorm" itemValue="Thunderstorm" />
                                    <f:selectItem itemLabel="Snow" itemValue="Snow" />
                                    <f:selectItem itemLabel="Mist" itemValue="Mist" />                            
                                </p:selectManyCheckbox>                                
                            </p:inplace>
                            <p:outputLabel for="country" value="Organizer:" />
                            <h:outputText id="creator" value="#{eventBean.event.creator.username} (#{eventBean.event.creator.name} #{eventBean.event.creator.surname})"/>
                            
                            <p:outputLabel for="created" value="Created:" />
                            <h:outputText id="created" value="#{eventBean.event.creationTimestamp}"/>
                            
                            <p:outputLabel for="partecipantsNumber"  value="Number of participants:" />
                            <h:outputText id="partecipantsNumber" value="#{eventBean.currentPartecipantsNumber}"/>
                        </h:panelGrid>
                        
                        <p:commandButton value="Save changes" id="saveChanges" update="form" actionListener="#{eventBean.saveChanges}" rendered="#{eventBean.isCreator}"/>
                        <p:commandButton value="Delete event" id="deleteEvent" update="form" action="#{eventBean.delete}" actionListener="#{eventBean.confirmDelete}" style="float: right" rendered="#{eventBean.isCreator}">
                            <p:confirm header="Confirmation" message="Delete this event?" icon="ui-icon-alert" />
                        </p:commandButton>
                        <p:confirmDialog global="true" showEffect="fade">
                            <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                            <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                        </p:confirmDialog>
                        
                        <p:separator/>
                        <p:panel header="Weather forecast">
                                <h:outputText value="#{eventBean.weatherForecast}" style="font-weight: bold"/>
                        </p:panel>

                        <p:separator rendered="#{eventBean.isCreator}"/>
                        
                        <p:panel header="Invitations" rendered="#{eventBean.isCreator}">
                            <p:dataList value="#{eventBean.currentInvitations}" var="invitation" type="unordered" emptyMessage="No user invited">
                                #{invitation.user.username}, #{invitation.accepted ? "accepted" : "not accepted"}             
                            </p:dataList>
                            <p>
                            <p:selectCheckboxMenu id="invitationMenu" value="#{eventBean.newInvitations}" label="Users" filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
                                <f:selectItems value="#{eventBean.newPossibleInvitations}" />
                            </p:selectCheckboxMenu>                            
                            <p:commandButton value="Send new invitations" id="sendNewInvitations" update=":form" action="#{eventBean.addNewInvitations}" style="float: right"/>    
                            </p>
                        </p:panel>
                        
                        <p:separator rendered="#{eventBean.invited}"/>
                        
                        <p:panel id="basic" header="My invitation" style="margin-bottom:20px" rendered="#{eventBean.invited}">
                            <p:outputLabel for="invitationResponse" value="You are invited to this event. Accept? "/>
                            <p:selectBooleanButton  id="invitationResponse" value="#{eventBean.invitation.accepted}"  onLabel="Yes" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close"  style="width:80px">
                                <p:ajax update=":form"  listener="#{eventBean.changeInvitation}"/>
                            </p:selectBooleanButton>
                        </p:panel>
 
                    </h:form>
                </p:panel>
                <p:panel rendered="#{not eventBean.eventExists}">
                    <h:outputText value="This event does not exists"/>
                </p:panel>
                <p:panel rendered="#{eventBean.eventExists and eventBean.event.deleted}">
                    <h:outputText value="This event has been deleted by its creator"/>
                </p:panel>
            </ui:define>

        </ui:composition>

    </body>
</html>
